import Vue from 'vue'
import Router from 'vue-router'

// 重写 router push 方法，路由往同一地址跳转时会报错的情况
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}


Vue.use(Router)

const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  {
    path:'/login',
    name: 'Login',
    component: ()=>import('views/Login.vue')
  },
  {
    path:'/home',
    name:'Home',
    component: ()=>import('views/home/Home.vue'),
    redirect:'/users',
    children:[
      {
        path:'/users',
        name: 'Users',
        component: ()=>import('views/user/Users.vue')
      },
      {
        path:'/roles',
        name:'Roles',
        component:()=>import('views/roles/Rules.vue')
      }
    ]
  }
]

const router = new Router({
  routes
})

export default router
